package war;

import java.security.SecureRandom;
import java.util.*;

public class Deck {

  private final Random random = new SecureRandom();
  private final List<Integer> cards = new LinkedList<Integer>();
  
  //Declare Class Card and variable Weight. (added by Robbin@20140923)
  private Card card;
  private int weight;
  
  public Deck() {
	//Instance Class Card and weight (added by Robbin@20140923)
	card = new Card();
	weight = 0;
	
    for (int i = 0; i < 4; i++) {
    	
      //Get weight of color(added by Robbin@20140923) add
      weight = card.getWeightByColor(i);
      
      for (int j = 1; j <= 13; j++) {
    	//Plus weight to cards(modified by Robbin@20140923)
        cards.add(j + weight);
      }
    }
  }

  public Deck(List<Integer> cards) {
    this.cards.addAll(cards);
  }

  public Deck(Integer... cards) {
    this.cards.addAll(Arrays.asList(cards));
  }

  public void shuffle() {
    Collections.shuffle(cards, random);
  }

  public List<Deck> split() {
    List<Deck> decks = new ArrayList<Deck>();
    int half = cards.size() / 2;
    int otherHalf = cards.size() - half;
    decks.add(new Deck(cards.subList(0, half)));
    decks.add(new Deck(cards.subList(half, half + otherHalf)));
    return decks;
  }

  public int size() {
    return cards.size();
  }

  public int drawCard() {
    return cards.remove(0);
  }

  public int peekCard() {
    return cards.get(0);
  }

  public void addCards(Integer... card) {
    cards.addAll(Arrays.asList(card));
  }

}
